

package com.mt.restaurant.controller.sale;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.restaurant.dto.sale.VegetableMenuEditDto;
import com.mt.restaurant.entity.sale.VegetableMenu;
import com.mt.restaurant.service.sale.VegetableMenuService;
							

@Api(tags = "菜谱")
@RestController
@RequestMapping("/api/restaurant/sale/VegetableMenu")
@CrossOrigin(allowCredentials = "true")
public class VegetableMenuController {
private static Logger logger = LoggerFactory.getLogger(VegetableMenuController.class);



																								@Autowired private VegetableMenuService vegetableMenuService;
	
	/**
	* 根据分页参数查询菜谱集合
	*
	* @param pageDTO 分页条件
	*/
	//@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:view')")
	@ApiOperation("分页查询菜谱")
	@ApiPageParam
	@PostMapping("/findVegetableMenus")
	public PageResultDTO findVegetableMenus(@RequestBody PageDTO pageDTO){
		return this.vegetableMenuService.findVegetableMenus(pageDTO);
	}

	/**
	* 根据分页参数查询菜谱集合
	*
	* @param pageDTO 分页条件
	*/
	//@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:view')")
	@ApiOperation("分页查询菜谱")
	@ApiPageParam
	@PostMapping("/findVegetableMenusWithCost")
	public PageResultDTO findVegetableMenusWithCost(@RequestBody PageDTO pageDTO){
		return this.vegetableMenuService.findVegetableMenusWithCost(pageDTO);
	}

	/**
	* 根据ID查询指定的菜谱
	*
	* @param vegetableMenuId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:view')")
	@ApiOperation("根据id查询菜谱")
	@ApiPageParam
	@PostMapping("/findVegetableMenu")
	public VegetableMenu findVegetableMenu(@RequestParam Long vegetableMenuId){
		return this.vegetableMenuService.findVegetableMenu(vegetableMenuId);
	}

	/**
	* 根据ID查询指定的菜谱(包含外键名称)
	*
	* @param vegetableMenuId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:view')")
	@ApiOperation("根据ID查询指定的菜谱(包含外键名称)")
	@PostMapping("/findVegetableMenuForView")
	public VegetableMenu findVegetableMenuForView(@RequestParam Long vegetableMenuId){
		return this.vegetableMenuService.findVegetableMenuWithForeignName(vegetableMenuId);
	}

	/**
	* 根据ID查询指定的菜谱(包含菜谱和外键名称)
	*
	* @param vegetableMenuId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:view')")
	@ApiOperation("根据ID查询指定的菜谱(包含菜谱和外键名称)")
	@PostMapping("/findVegetableMenuForEdit")
	public VegetableMenuEditDto findVegetableMenuForEdit(@RequestParam Long vegetableMenuId){
				VegetableMenuEditDto vegetableMenuEditDto = new VegetableMenuEditDto();
		vegetableMenuEditDto.setVegetableMenu(this.vegetableMenuService.findVegetableMenuWithForeignName(vegetableMenuId));

		this.prepareVegetableMenuEditDto(vegetableMenuEditDto);

		return vegetableMenuEditDto;
	}

	/**
	* 根据ID查询指定的菜谱(只提取ID 和 Name)
	*
	* @param vegetableMenuId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:view')")
	@ApiOperation("根据ID查询指定的菜谱(只提取ID 和 Name)")
	@PostMapping("/findVegetableMenusWithIdNameById")
	public VegetableMenu findVegetableMenusWithIdNameById(@RequestParam Long vegetableMenuId){
	return this.vegetableMenuService.findVegetableMenusWithIdNameById(vegetableMenuId);
	}

	/**
	* 根据名称查询菜谱集合(只提取ID 和 Name)
	*
	* @param vegetableMenuName 名称
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:view')")
	@ApiOperation("根据名称查询菜谱集合(只提取ID 和 Name)")
	@PostMapping("/findVegetableMenusWithIdNameByName")
	public List<VegetableMenu> findVegetableMenusWithIdNameByName(@RequestParam String vegetableMenuName){
	return this.vegetableMenuService.findVegetableMenusWithIdNameByName(vegetableMenuName);
	}


	/**
	* 创建新的菜谱
	*
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:add')")
	@ApiOperation("创建新的菜谱")
	@PostMapping("/createVegetableMenu")
	public VegetableMenuEditDto createVegetableMenu(){
				VegetableMenuEditDto vegetableMenuEditDto = new VegetableMenuEditDto();
		vegetableMenuEditDto.setVegetableMenu(new VegetableMenu());

		this.prepareVegetableMenuEditDto(vegetableMenuEditDto);
		return vegetableMenuEditDto;
	}

	private void prepareVegetableMenuEditDto(VegetableMenuEditDto vegetableMenuEditDto){
																							}

	/**
	* 新增保存菜谱
	*
	* @param vegetableMenu 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:add')")
	@ApiOperation("新增保存菜谱")
	@PostMapping("/saveVegetableMenu")
	public VegetableMenu saveVegetableMenu(@RequestBody VegetableMenu vegetableMenu){
		return this.vegetableMenuService.saveVegetableMenu(vegetableMenu);
	}

	/**
	* 修改保存菜谱
	*
	* @param vegetableMenu 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:update')")
	@ApiOperation("修改保存菜谱")
	@PostMapping("/updateVegetableMenu")
	public VegetableMenu updateVegetableMenu(@RequestBody VegetableMenu vegetableMenu){
		return this.vegetableMenuService.updateVegetableMenu(vegetableMenu);
	}

	/**
	* 根据ID删除菜谱
	*
	* @param vegetableMenuId ID
	*/
	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:remove')")
	@ApiOperation("根据ID删除菜谱")
	@PostMapping("/deleteVegetableMenu")
	public void deleteVegetableMenu(@RequestParam Long vegetableMenuId){
		this.vegetableMenuService.deleteVegetableMenu(vegetableMenuId);
	}

	@PreAuthorize("hasAuthority('restaurant:sale:VegetableMenu:add')")
	@ApiOperation("新增菜谱")
	@PostMapping("/addNewMenu")
	public void addNewMenu(@RequestBody VegetableMenu vegetableMenu){
		this.vegetableMenuService.addNewMenu(vegetableMenu);
	}


}

